package org.ruanjj.multithread.JUC;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolDemo {
    public static void main(String[] args) {


        try(     ThreadPoolExecutor pool = new ThreadPoolExecutor(
                2,
                5,
                2L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());
          ) {

            for(int i = 1; i<= 8; i++) {
                pool.execute(() -> {
                    System.out.println(Thread.currentThread().getName() + "办理业务");
                });
            }

            for(int i = 1; i<= 8; i++) {
                pool.execute(() -> {
                    System.out.println(Thread.currentThread().getName() + "咨询业务");
                });
            }
        }
    }
}
